package hanqi.llbrary.Service;


import hanqi.llbrary.DAO.BookDAO;
import hanqi.llbrary.entity.book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class bookServiceImpl implements bookService {
  @Autowired
  private BookDAO bookRepository;
  @Override
  public List<book> findAll() {
   return bookRepository.findAll();
  }
  @Override
  public book findById(Long id) {
   return bookRepository.getById(id);
  }
  @Override
  public void save(book book) {
   bookRepository.save(book);
  }
  @Override
  public void update(book book) {
   bookRepository.save(book);
  }
  @Override
  public void deleteById(Long id) {
 bookRepository.deleteById(id);
  }
  @Override
  public List<book> findByTitle(String title) {
  return bookRepository.findByTitleContains(title.trim());
  }
  @Override
  public String getPublisherNameById(Long id) {
  book book = bookRepository.getById(id);
        if (book != null) {
    return book.getPublisher().getPublisherName();
   }
   return null;
  }
  @Override
  public List<String> findAuthorList() {
  return bookRepository.getAuthorList();
  }

}
